import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/3/21 22:27
 */

public class Solution {
    public int maxArea(int[] height){
        int left = 0,right = height.length - 1,ret = 0;
        while(left < right){
            int volume = (right - left) * Math.min(height[left], height[right]);
            if(height[left] > height[right])
                right--;
            else
                left++;
            ret = Math.max(ret,volume);
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int len = in.nextInt();
            int[] height = new int[len];
            for (int i = 0; i < len; i++) {
                height[i] = in.nextInt();
            }
            Solution solution = new Solution();
            System.out.println(solution.maxArea(height));
        }
    }
}
